package org.example.service.Impl;

import org.example.bean.*;
import org.example.mapper.ModulesMapper;
import org.example.service.ModulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class ModulesServiceImpl implements ModulesService {
    @Autowired
    private ModulesMapper modulesMapper;

    @Override
    public List<Modules> findModule(Integer m_id) {
        return modulesMapper.findModules(m_id);
    }

    @Override
    public List<ModuleList> findAll() {
        return modulesMapper.findAll();
    }

    @Override
    public List<Product> findAllProduct() {
        return modulesMapper.findAllProduct();
    }

    @Override
    public List<Supplier> findAllSupplier() {
        return modulesMapper.findAllSupplier();
    }

    @Override
    public Integer addModuleList(String mName) {
        modulesMapper.addModuleList(mName.trim());
        return modulesMapper.getId();
    }

    @Override
    public boolean addModules(Integer mId, String supplier, String breed, Integer finalist, Integer nowFix) {
        return modulesMapper.addModules(mId,supplier,breed,finalist,nowFix);
    }

    @Override
    public boolean del(Integer mId) {
        modulesMapper.delModules(mId);
        return modulesMapper.delList(mId)>0;
    }

    @Override
    public List<Ship> shopAll() {
        return modulesMapper.shopAll();
    }

    @Override
    public Integer ordersAll(Orders orders) {
        Random rd = new Random();
        int randomNumber = rd.nextInt(1000) + 1; // 生成1到100之间的随机数
        String oNumber = "KGH" + randomNumber;
        modulesMapper.ordersAll(orders, oNumber);
        return modulesMapper.getMId(oNumber);
    }

    @Override
    public Integer addSup(Sup sup) {
        return modulesMapper.addSup(sup);
    }

    @Override
    public List<Sup> supSer(Integer oId) {
        return modulesMapper.supSer(oId);
    }

    @Override
    public Integer addOD(Integer oId, String breed, Integer price, Integer purchaseQuantity) {
        return modulesMapper.addOD(oId,breed.replace("\"",""),price,purchaseQuantity);
    }

    @Override
    public List<OrderDetailed> OrderDetailedId(Integer oId) {
        return modulesMapper.OrderDetailedId(oId);
    }

    @Override
    public boolean updateODPrice(Integer oId,String breed, Integer price) {
        return modulesMapper.updateODPrice(oId,breed.replace("\"",""),price);
    }

    @Override
    public boolean deleteSO(Integer oId) {
        modulesMapper.deleteO(oId);
        return modulesMapper.deleteS(oId)>0;
    }


}
